package org.zephy.guomi;

import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SmUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.SM2;

/**
 * 随机生成的密钥对进行加密解密
 */
public class Sm2Test1 {
    public static void main(String[] args) {
        String text="this is a test str";
        SM2 sm2= SmUtil.sm2();
        //公钥加密，私钥解密
        KeyType publicKey=KeyType.PublicKey;
        System.out.println("公钥:"+publicKey.toString());
        KeyType privateKey=KeyType.PrivateKey;
        System.out.println("私钥:"+privateKey.toString());

        String encryptStr=sm2.encryptBcd(text,publicKey);

        String decryptStr= StrUtil.utf8Str(sm2.decryptFromBcd(encryptStr,privateKey));

        System.out.println("encode:"+encryptStr);

        System.out.println("decode:"+decryptStr);

    }
}
